package cn.imvc.app.controllers.goods;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import cn.imvc.app.entities.GoodsClass;
import cn.imvc.app.entities.GoodsClassAttr;
import cn.imvc.app.models.AttrClassModel;
import cn.imvc.app.models.GoodsClassAttrModel;
import cn.imvc.app.models.GoodsClassModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

/**
 * 
 * @author zhy
 * @date 2016年8月4日下午2:38:42
 *
 */
public class GoodsClassAttrControllerImpl implements GoodsClassAttrController{

	public Page<GoodsClassAttr> page;
	public ViewRequest viewRequest;
	public GoodsClassAttr goodsClassAttr;
	public int id;
	public int[] ids;
	public GoodsClass goodsClass;
	public int goodsClassId;
	@Autowired
	GoodsClassAttrModel goodsClassAttrModel;
	@Autowired
	GoodsClassModel goodsClassModel;
	public String search() {
		return null;
	}

	public String index() {
		Map<String,String> searchMap = new HashMap<String,String>();
		searchMap.put("goodsClassId_eq_string", String.valueOf(goodsClassId));
		viewRequest = new ViewRequest();
		viewRequest.setParams(searchMap);
		page = goodsClassAttrModel.find(viewRequest);
		return "goods-class-attr/index";
	}

	public String show() {
		return null;
	}

	public String editNew() {
		goodsClass = goodsClassModel.get(goodsClassId);
		return "goods-class-attr/edit";
	}

	public String create() {
		goodsClassAttr.setGoodsClass(goodsClassModel.get(goodsClassId));
		int result = goodsClassAttrModel.save(goodsClassId,goodsClassAttr);
		if(result==-1){
			return Render.json(new DialogBean("300","该属性已添加","goods_class_attr","closeCurrent"));
		}
		return Render.json(new DialogBean("200","添加成功","goods_class_attr","closeCurrent"));
	}

	public String edit() {
		goodsClassAttr = goodsClassAttrModel.get(id);
		goodsClass = goodsClassAttr.getGoodsClass();
		return "goods-class-attr/edit";
	}

	public String update() {
		goodsClassAttr.setGoodsClass(goodsClassModel.get(goodsClassId));
		int result = goodsClassAttrModel.update(id,goodsClassId,goodsClassAttr);
		if(result==-1){
			return Render.json(new DialogBean("300","该属性已添加","goods_class_attr","closeCurrent"));
		}
		return Render.json(new DialogBean("200","修改成功","goods_class_attr","closeCurrent"));
	}

	public String destroy() {
		String result = goodsClassAttrModel.delete(id);
		if(result.equals("")){
		    return Render.json(new DialogBean("200","删除成功","goods_class_attr"));
		}else{
			return Render.json(new DialogBean("300",result,"goods_class_attr"));
		}
	}

	public String destroyBatch() {
		goodsClassAttrModel.deleteBatch(ids);
		return Render.json(new DialogBean("200","删除成功","goods_class_attr"));
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public GoodsClassAttr getGoodsClassAttr() {
		return goodsClassAttr;
	}

	public void setGoodsClassAttr(GoodsClassAttr goodsClassAttr) {
		this.goodsClassAttr = goodsClassAttr;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public GoodsClass getGoodsClass() {
		return goodsClass;
	}

	public void setGoodsClass(GoodsClass goodsClass) {
		this.goodsClass = goodsClass;
	}

	public int getGoodsClassId() {
		return goodsClassId;
	}

	public void setGoodsClassId(int goodsClassId) {
		this.goodsClassId = goodsClassId;
	}



}
